package com.yisu.auction.api.core.service.impl;

import com.yisu.auction.api.core.mapper.OfferPriceLogArchiveMapper;
import com.yisu.auction.api.core.mapper.OfferPriceLogMapper;
import com.yisu.auction.api.core.service.BaseService;
import com.yisu.auction.api.core.service.IOfferPriceLogService;
import com.yisu.auction.api.domain.request.prizePackage.PrizeDetailRequest;
import com.yisu.auction.api.domain.vo.goodsInfoPackageVos.ClosingBidRecordVo;
import com.yisu.auction.api.domain.vo.goodsInfoPackageVos.OfferPriceVo;
import com.yisu.auction.ewf.entity.OfferPriceLog;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * author: 赵杰
 * Business Description：出价流水相关业务实现
 * createTime：2017/8/17
 */
@Service("IOfferPriceLogService")
public class OfferPriceLogServiceImpl extends BaseService implements IOfferPriceLogService {
    @Resource
    private OfferPriceLogMapper offerPriceLogMapper;
    @Resource
    private OfferPriceLogArchiveMapper offerPriceLogArchiveMapper;

    /**
     * author: 赵杰
     * Business Description：通过会员memberId和prizeId 获取用户出价总额
     *
     * @param prizeDetailRequest 含会员 ID   prizeId
     * @return
     */
    @Override
    public BigDecimal getUserOfferPriceByPrizeId(PrizeDetailRequest prizeDetailRequest) {
        return offerPriceLogMapper.getUserOfferPriceByPrizeId(prizeDetailRequest);
    }

    /**
     * author: 赵杰
     * Business Description：通过prizeId 获取此拍品出价流水
     *
     * @param prizeDetailRequest 含prizeId
     * @return
     */
    @Override
    public List<OfferPriceVo> getOfferPriceLogListByPrizeId(PrizeDetailRequest prizeDetailRequest) {
        List<OfferPriceVo> offerPriceVos = offerPriceLogMapper.getOfferPriceLogListByPrizeId(prizeDetailRequest);
        if (CollectionUtils.isEmpty(offerPriceVos)) {
            return offerPriceLogArchiveMapper.getOfferPriceLogListByPrizeId(prizeDetailRequest);
        } else {
            return offerPriceLogMapper.getOfferPriceLogListByPrizeId(prizeDetailRequest);
        }
    }

    /**
     * author: 赵杰
     * Business Description：通过prizeId最后出价记录
     *
     * @param prizeId
     * @return
     */
    @Override
    public ClosingBidRecordVo getClosingBidRecordByPrizeId(long prizeId) {
        return offerPriceLogMapper.getClosingBidRecordByPrizeId(prizeId);
    }

    /**
     * 获取数据库时间-为所有倒计时服务
     *
     * @return
     */
    @Override
    public Date getDbDate() {
        return offerPriceLogMapper.getDbDate();
    }
}
